namespace Org.Loon.Framework.Xna.Game.Action
{

    public class RotateTo : ActionEvent
    {

        private float dstAngle;

        private float diffAngle;

        private float startAngle;

        private float speed;

        public RotateTo(float d, float s)
        {
            this.dstAngle = d;
            if (this.dstAngle > 360)
            {
                this.dstAngle = 360;
            }
            else if (this.dstAngle < 0)
            {
                this.dstAngle = 0;
            }
            this.speed = s;
        }

        public override bool IsComplete()
        {
            return isComplete;
        }

        public override void OnLoad()
        {
            startAngle = original.GetRotation();
            diffAngle = 1;
        }

        public override void Update(long elapsedTime)
        {
            startAngle += diffAngle * speed;
            original.SetRotation(startAngle);
            if (startAngle >= dstAngle)
            {
                isComplete = true;
            }
        }

    }
}
